package com.risetek.tft.entity;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * TRole entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "T_SYS_ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class TRole extends BaseEntity2 implements java.io.Serializable {

	// Fields

	private String name;
	private String code;
	private String remark;
	private Set<TOperate> TOperates = new HashSet<TOperate>(0);
	private Set<TManager> TManagers = new HashSet<TManager>(0);

	// Constructors

	/** default constructor */
	public TRole() {
	}

	/** minimal constructor */
	public TRole(String name) {
		this.name = name;
	}

	/** full constructor */
	public TRole(String name, String code, String remark,
			Set<TOperate> TOperates, Set<TManager> TManagers) {
		this.name = name;
		this.code = code;
		this.remark = remark;
		this.TOperates = TOperates;
		this.TManagers = TManagers;
	}

	// Property accessors
	 

	@Column(name = "NAME", nullable = false, length = 50)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "CODE", length = 50)
	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "REMARK", length = 2000)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY  )
	@JoinTable(name = "T_SYS_ROLE_OPERATE", joinColumns = { @JoinColumn(name = "role", nullable = false, updatable = false) }, 
	inverseJoinColumns = { @JoinColumn(name = "menu", nullable = false, updatable = false), @JoinColumn(name = "op", nullable = false, updatable = false) })
	public Set<TOperate> getTOperates() {
		return this.TOperates;
	}

	public void setTOperates(Set<TOperate> TOperates) {
		this.TOperates = TOperates;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "TRole")
	public Set<TManager> getTManagers() {
		return this.TManagers;
	}

	public void setTManagers(Set<TManager> TManagers) {
		this.TManagers = TManagers;
	}

}